/**
 *
 */
package pt.iscte.iul.dcti.pa.gspas.gui.listener;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.swing.JPanel;

import pt.iscte.iul.dcti.pa.gspas.util.Property;
import pt.iscte.iul.dcti.pa.gspas.util.SwingUtils;

/**
 * @author Gedsimon Pereira - 58554
 * @contact gspas@iscte.pt
 *
 */
public class CollectionMouseListener implements MouseListener {

    private Object object;
    private Property property;
    private JPanel panel;

    public CollectionMouseListener(Object object, Property property,
            JPanel panel) {
        this.object = object;
        this.property = property;
        this.panel = panel;
    }

    @Override
    public void mouseReleased(MouseEvent e) {
    }

    @Override
    public void mousePressed(MouseEvent e) {
    }

    @Override
    public void mouseExited(MouseEvent e) {
    }

    @Override
    public void mouseEntered(MouseEvent e) {
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        renderPannelRight(object, property);
    }

    private void renderPannelRight(Object inputObject, Property property) {
        Collection listOfObject = property.getValue(inputObject,
                Collection.class);

        if (listOfObject != null && listOfObject.size() > 0) {
            panel.removeAll();
            for (Object object : listOfObject) {
                panel.add(SwingUtils.createLabel(object.toString()));
            }
            panel.setLayout(new java.awt.GridLayout(listOfObject.size(), 1));
            panel.revalidate();
        }
    }

    private void renderPannelRightWithTable(Object inputObject, Property property) {
        Collection listOfObject = property.getValue(inputObject,
                Collection.class);
        //This may take a npe
        List<Property> lst = Property.getProperties(listOfObject.iterator().next().getClass());
        String[] columnNames = new String[lst.size()];
        int count = 0;
        for (Property prt : lst) {
            columnNames[0] = prt.getLabel();
            count++;
        }
    }
}
